package com.caiden_micheal.user.web;

import com.caiden_micheal.base.aop.annotation.PermissionVerify;
import com.caiden_micheal.base.domain.AjxResult;
import com.caiden_micheal.user.service.UserService;
import com.caiden_micheal.user.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PermissionVerify(permissionArray = {"sys:userManagement", "sys:orgManagement:viewMember"})
    @PostMapping("/userQuery")
    public AjxResult userInfoPageQuery(@RequestBody UserQueryVO userQueryVO) {
        return AjxResult.success(userService.findUsersByCondition(userQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:positionManagement:viewMember"})
    @PostMapping("/userQueryByPosition")
    public AjxResult userQueryByPosition(@RequestBody UserQueryVO userQueryVO) {
        return AjxResult.success(userService.findUsersByPositionCondition(userQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:orgManagement:addMember"})
    @PostMapping("/userQueryUnOrg")
    public AjxResult userQueryUnOrg(@RequestBody UserQueryVO userQueryVO) {
        userQueryVO.setUnOrgFlag(true);
        return AjxResult.success(userService.findUsersByCondition(userQueryVO));
    }

    @PostMapping("/userQueryUnPosition")
    public AjxResult userQueryUnPosition(@RequestBody UserQueryVO userQueryVO) {
        return AjxResult.success(userService.findUsersByExcludePositionCondition(userQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:userManagement:add"})
    @PostMapping("/addUser")
    public AjxResult addUser(@RequestBody UserAddVO userAddVO) {
        return userService.addUser(userAddVO);
    }

    @PermissionVerify(permissionArray = {"sys:userManagement:edit"})
    @PostMapping("/editUser")
    public AjxResult editUser(@RequestBody UserEditVO userEditVO) {
        return userService.editUser(userEditVO);
    }

    @PermissionVerify(permissionArray = {"sys:userManagement:edit"})
    @PostMapping("/findUserEncryption")
    public AjxResult findUserDecryptDataById(@RequestBody FindUserEncryptionVO data) {
        return userService.findUserDecryptDataById(data.getUserId());
    }

    @PermissionVerify(permissionArray = {"sys:userManagement:assignPermission"})
    @PostMapping("/userRemoveAuthority")
    public AjxResult userRemoveAuthority(@RequestBody RemoveUserPermissionVO removeUserPermissionVO) {
        return userService.userRemoveAuthority(removeUserPermissionVO);
    }

    @PermissionVerify(permissionArray = {"sys:userManagement:assignPermission"})
    @PostMapping("/userAddPermission")
    public AjxResult userAddPermission(@RequestBody UserAddPermissionVO userAddPermissionVO) {
        return userService.userAddPermission(userAddPermissionVO);
    }
}